<?php

declare(strict_types=1);

namespace app\model;

use app\api\service\OilStoreService;
use think\model\concern\SoftDelete;

/**
 * 
 *
 * @mixin \think\Model
 * @property int $id
 * @property string $name
 * @property int $agent_id
 * @property bool $status 状态 0 关闭 1 启用
 * @property string $memo
 * @property string $created_at
 * @property string $updated_at
 * @property string $deleted_at
 * @property-read mixed $url
 * @property-read \app\model\OilOrder[] $order
 * @property-read \app\model\Agent $agent
 * @method static \think\db\Query onlyTrashed()
 * @method static \think\db\Query withTrashed()
 */
class OilAgentChannel extends CommonModel
{
    use SoftDelete;

    public function getUrlAttr($value, $data)
    {
        $urlData = invoke(OilStoreService::class)->makeH5Url($data['id']);

        return $urlData['data']['h5'];
    }

    public function order()
    {
        return $this->hasMany(OilOrder::class, 'cnid');
    }

    public function agent()
    {
        return $this->belongsTo(Agent::class, 'agent_id');
    }
}
